home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 41
/
Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso
/
Aminet
/
comm
/
net
/
tf02.lha
/
TinyFugue
/
tf-lib
/
factoral.tf
< prev
next >
Wrap
Text File
|
1995-08-12
|
688b
|
29 lines
;;;; factorial macros
;;; Not very useful, but they do demonstrate some macro programming techniques.
;; recursive factorial
/def rfact = \
/if ( {1} < 0 ) \
/echo %% factorial: negative argument%; \
/elseif ( {1} == 0 ) \
/echo 1%; \
/else \
/eval /echo -- $$[{1} * $(/rfact $[{1} - 1])]%; \
/endif
;; iterative factorial - more efficient
/def ifact = \
/if ( {1} < 0 ) \
/echo %% factorial: negative argument%; \
/else \
/let n=%1%; \
/let result=1%; \
/while (n) \
/let result=$[result * n]%; \
/let n=$[n - 1]%; \
/done%; \
/echo -- %result%; \
/endif%; \